<template>
    <div>
        费用主记录（项目共计：<span class="mr5" style="color: blue">{{
            clinicOrdersList.length
        }}</span>个|| 费用总计：<span class="ml5 mr5" style="color: blue">{{
            sumPrice.toFixed(2)
        }}</span>元）
    </div>
    <el-table ref="clinicOrdersRef" :border="true" :data="clinicOrdersList" :header-cell-style="$headerCellStyle" :stripe="true"
              height="93%" highlight-current-row @selection-change="handleSelectionChange">
        <el-table-column :align="'center'" type="selection" width="55"/>
        <el-table-column :align="'center'" label="项目类型" prop="itemClass" width="90">
            <template #default="scope">
                <dict-data-tag :options="dictDataMap['bill_item_class_dict']" :value="scope.row.itemClass"/>
            </template>
        </el-table-column>
        <el-table-column :align="'center'" label="申请单号" prop="applyNo" width="120"/>
        <el-table-column :align="'center'" :show-overflow-tooltip="true" label="申请时间" prop="createTime"
                         width="170"/>
        <el-table-column :align="'center'" label="申请科室" prop="applyDeptName" width="120"/>
        <el-table-column :align="'center'" label="申请人" prop="applyUserName" width="120"/>
        <el-table-column :align="'center'" label="执行科室" prop="implementDeptName" width="130"/>
        <el-table-column :align="'center'" label="应收" prop="costs" width="130">
            <template #default="scope">
                <span class="ys-css">{{ parseFloat(scope.row.costs).toFixed(2) }}</span>元
            </template>
        </el-table-column>
        <el-table-column :align="'center'" label="实收" prop="charges" width="130">
            <template #default="scope">
                <span class="ys-css">{{ parseFloat(scope.row.charges).toFixed(2) }}</span>元
            </template>
        </el-table-column>
        <el-table-column :align="'center'" label="诊断信息" min-width="251" prop="diagnosis"/>
    </el-table>
</template>
<script lang="ts">
export default {
    name: "ClinicOrders",
};
</script>

<script setup lang="ts">
import {listClinicOrders} from "@/api/clinicOrder/clinicOrders";
import {useDictStoreHook} from "@/store/modules/dict";

const dictStore = useDictStoreHook();
let dictDataMap = ref(
    dictStore.isTypeGetData("charge_flag_dict", "bill_item_class_dict", "sys_yes_no")
);

const {proxy} = getCurrentInstance() as any;
const clinicOrdersRef = ref();
const props = defineProps({
    clinicId: {
        type: String,
        default: "",
    },
    orgId: {
        type: String,
        default: "",
    },
});
const sumPrice = ref<Number>(0.0);
const emits = defineEmits(["ordersSelectionChange"]);
const clinicOrdersList = ref<any>([]);
const ids = ref([]);

watch(
    () => props.clinicId,
    (nowValue) => {
        if (nowValue) {
            getList(nowValue);
        } else {
            clinicOrdersList.value = [];
        }
    }
);

/** 查询门诊医嘱列表 */
function getList(nowValue: String) {
    clinicOrdersList.value = [];
    const queryParams = {
        clinicId: nowValue,
        orgId: props.orgId,
        chargeFlag: "1",
    };
    listClinicOrders(queryParams).then((response: resType) => {
        clinicOrdersList.value = response.data;
        let sum = 0.0;
        clinicOrdersList.value.forEach((item: any) => {
            sum += Number(item.charges);
        });
        sumPrice.value = sum;
        clinicOrdersRef.value.toggleAllSelection();
    });
}

function handleSelectionChange(selection) {
    ids.value = selection.map((item) => item.id);
    emits("ordersSelectionChange", ids.value);
}
</script>
